public class spisok {
	
		public element head = null;
		
		public void delbeg(element elem)
		{
			if(head == null)
			{
				head = elem;
			}
			else 
			{
				head=null;
				elem=null;
			}
		}
		
		public void delend(element elem){
			if(head == null)
			{
				head = elem;
			}
			else 
			{
				element cur = head;
			while(cur.next.next != null){
				
				cur = cur.next;
			}
			cur.next=null;
			}
		}
		
		public void bubblesort(element elem)
		{
			boolean swapped = true;
			int j = 0;
			if(head == null){
				head = elem;
			}
			else 
			{
				element cur = head;
				while(cur.next != null){
					do
					{
						if(j!=0)
						{
							j=0;
							cur = head;
						}
						swapped = false;
						if(cur.i>cur.next.i)
						{
							j++;
							int tmp = cur.i;
							cur.i = cur.next.i;
							cur.next.i = tmp;
							swapped = true;
							}
						}
					while(swapped);
					cur = cur.next;	
					}
				}
			}
		
		public void addafter(element elem ,int elem1)
		{
			if(head == null)
			{
				head = elem;
			}
			else 
			{
				element cur = head;
				while(cur.next != null)
				{
					if(cur.i == elem1)
					{
						elem.next=cur.next;
						cur.next=elem;
						return;
					}
					cur = cur.next;
				}
			}
		}
		
		public void addstart(element elem)
		{
			if(head == null)
			{
				head = elem;
			}
			else
			{
				elem.next = head;
				head =  elem;
			}
		}
		
		public void addend(element elem)
		{
			if(head == null)
			{
				head = elem;
			}
			else 
			{
				element cur = head;
				while(cur.next != null)
				{
					cur = cur.next;
				}
				cur.next = elem;
			}
		}
		
		public String toString()
		{
			StringBuffer sb= new StringBuffer();
			sb.append("[");
			element current = head;
			while (current != null)
			{
				sb.append(current.i + " ");
				current = current.next;
			}
			sb.append("]");
			return sb.toString();
		}
	
}
